package com.b3434.Processor;

import com.alibaba.fastjson.JSONObject;
import com.b3434.Service.BlackListService;
import org.apache.avro.generic.GenericRecord;

import java.util.List;

/**
 * Created by Lee on 2017/3/29 0029.
 */
public class WhiteListProcessor extends Processor{
    Processor processor;

    public WhiteListProcessor(Processor processor) {
        this.processor = processor;
        this.parameter = processor.parameter;
    }

    @Override
    public GenericRecord process(String originStr) {
        dataMap = processor.process(originStr);
        JSONObject jsonObject = JSONObject.parseObject(originStr);
        List<String> whiteList = parameter.getWhiteList();
        BlackListService blackListService = new BlackListService(parameter);
        for (String i : whiteList) {
            if (jsonObject.containsKey(i)&&!blackListService.checkFiledInBlackList(i)) {
                dataMap.put(i, jsonObject.getString(i));
            }
        }
        return dataMap;
    }
}
